home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / VIEWDISP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  3.0 KB  |  77 lines

  1. /* viewdisp.c file - displays current page of file */
  2. #include "stdio.h"
  3. #include "cminor.h"
  4. #include "viewparm.h"
  5.  
  6. #define TAB_WIDTH       8
  7. #define PAGE_WIDTH      80
  8. extern char filename[]  ;
  9. extern long filesize    ;       /* size of file in bytes        */
  10. extern long top_of_page ;       /* file position of top of page */
  11. int row ;                       /* current line of page         */
  12. int col ;                       /* current column of page       */
  13.  
  14.   display_page()
  15.   {
  16.     int c ;                     /* hold the character here      */
  17.     int i ;                     /* counter for loop             */
  18.  
  19.     move_to(top_of_page) ;      /* start at top of page         */
  20.                                 /* write a header line          */
  21.     printf("\n FILE - %s    POSITION - %1d     FILE SIZE - %1d \n",
  22.     filename,top_of_page,filesize);
  23.  
  24.                                 /* write a border line of dashes*/
  25.     for( i=1 ; i < 80 ; i = i + 1 )
  26.       { putchar('-') ; }
  27.  
  28.     /* get chars from file until we've written (PAGE_SIZE) lines */
  29.     /* or we've reached the end of the file                      */
  30.     row = 1 ;                   /* starting row and column values*/
  31.     col = 1 ;
  32.     c = get_next_char() ;
  33.     while( ( row <= PAGE_SIZE ) && ( c != EOF_MARK ) )
  34.       {                         /* write till end of page or file*/
  35.         disp_char(c) ;          /* display current character     */
  36.         c = get_next_char() ;   /* and get another one           */
  37.       }
  38.     while( row <= PAGE_SIZE )   /* pad out page if eof reached   */
  39.       { putchar('\n'); row = row + 1 ; }
  40.  
  41.     for( i=1 ; i < 80 ; i=i+1 ) /* write a border line of dashes */
  42.       { putchar('-') ; }
  43.   }
  44.  
  45.  
  46.   int disp_char(c)              /* display one character        */
  47.                                 /* and update row and column    */
  48.   int c ;                       /* value of char to write       */
  49.   {
  50.     /* classify the character and handle accordingly */
  51.  
  52.     if( isgraphic(c) )
  53.       { putchar(c) ;            /* display ASCII graphic char   */
  54.         col = col + 1 ;         /* advansc column number        */
  55.         if( col > PAGE_WIDTH )  /* check wrap-around            */
  56.           { row = row + 1 ;     /* yes - advance row number     */
  57.             col = 1 ;           /* set col to begining of line  */
  58.           }
  59.       }
  60.     else if( c == END_LINE )
  61.       { putchar('\n') ;         /* end_line char - force new line*/
  62.         row = row + 1 ;         /* advance row number           */
  63.         col = 1 ;               /* set column to first col  */
  64.       }
  65.     else if( c == '\t' )
  66.       {
  67.         do                      /* tab and expand it            */
  68.           { putchar(' ') ;      /* print spaces                 */
  69.             col = col + 1 ;     /* and advance column number    */
  70.             if( col > PAGE_WIDTH ) /* check wrap-around         */
  71.               { row = row + 1 ;
  72.                 col = 1 ;
  73.               }
  74.           } while( ( col % TAB_WIDTH ) != 1 ) ; /* until tab stop */
  75.       }
  76.   }
  77.